package com.example.service.impl;

import com.example.mapper.DeptMapper;
import com.example.mapper.EmpMapper;
import com.example.pojo.Dept;
import com.example.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_DaChiZi
 * Date: 2025/9/3
 * Time: 11:13
 */
@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    DeptMapper deptMapper;
    @Autowired
    EmpMapper empMapper;

    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }

    @Transactional
    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);

        empMapper.deleteById(id);
    }

    @Override
    public void insertByDeptName(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertByDeptName(dept);
    }

    @Override
    public void updateDeptName(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDeptName(dept);
    }

    @Override
    public Dept findById(Integer id) {
        Dept dept =  deptMapper.findById(id);
        return dept;
    }


}
